package com.lzy.sms.listener;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.lzy.sms.utils.SmsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @ClassName SmsListener
 * @Author liu zhiyong
 * @Date 2020/9/6 16:49
 * @Version 1.0
 */
@Component
public class SmsListener {

    @Autowired
    private SmsUtil smsUtil;

    @JmsListener(destination = "sms")
    public void sendSms(Map<String, String> map){
        try{
            //发送短信
            SendSmsResponse response = smsUtil.sendSms(map.get("mobilePhone"), map.get("signName"), map.get("templateCode"), map.get("templateParam"));
            System.out.println("成功向" + map.get("mobilePhone") + "发送一条短信");
            System.out.println("Code=" + response.getCode());
            System.out.println("Message=" + response.getMessage());
            System.out.println("RequestId=" + response.getRequestId());
            System.out.println("BizId=" + response.getBizId());

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
